package battleship.cxbr;

import java.util.ArrayList;

import battleship.emss.*;
/*
 * 			+---------------+
 * 			|	 Mission	|
 * 			+---------------+
 * 				/		\
 * 			   /		 \
 * 		+--------+		+---------+
 * 		| Search |		| Attack  |
 * 		+--------+		+---------+
 */
public class SearchContext extends Context
{
	protected int x;
	protected int y;
	protected int enemyX;
	protected int enemyY;
	protected int enemyTerritory;
	protected Status enemy;
	
	public SearchContext(String n,CxBRAgent a)
	{
		super(n,a);
	}
	
	//How to get here from above
	public double ParentRule(double Time)
	{
		
		return 0.0;
	}
	//How to get here from side
	public double SiblingRule(double Time)
	{
/*		for(int i=0;i<Agent.detectedStatus.size();i++)
		{
			Status tmpStatus=Agent.detectedStatus.get(i);
			//not on my team, and a sub
			//And I am close enough
			//and it is alive
			
			if(tmpStatus.team!=Agent.status.team && tmpStatus.type==Agent.SUB && tmpStatus.alive==1 && Math.sqrt(Math.pow(Agent.status.mx-tmpStatus.mx,2)+Math.pow(Agent.status.my-tmpStatus.my,2))>15*1600)
				return 1.0;
		}*/
		return 0.3;
		
	}
	
	//Things to do when just entering
	public void Initialize(double Time)
	{
		//start searching
		x=512;
		y=512;
	}

	
	//What do actually do
	public void Action(double Time)
	{
		Agent.status.status=Name;
		Agent.actions.clear();
		
		Agent.status.status+=" Searching";
 
		//detected others
		for(int i=0;i<Agent.detectedStatus.size();i++)
		{
			Status tmpStatus=Agent.detectedStatus.get(i);
			//not my team, and a sub
			if(tmpStatus.team!=Agent.status.team && tmpStatus.type==Agent.SUB)
			{
				enemy = tmpStatus;
				enemyX=tmpStatus.x;
				enemyY=tmpStatus.y;
				enemyTerritory=tmpStatus.territory;
			}
		}
		
			Agent.actions.add(new Move(Agent.status.x,Agent.status.y,enemyX,enemyY,3));
		return;
	}
	
}

